﻿<!DOCTYPE HTML>
<html xmlns:th="http://www.w3.org/1999/xhtml" xmlns:if="http://www.w3.org/1999/xhtml">
<!-- 插入公共模板 _meta -->
<head th:insert="../templates/admin/common/_meta :: common_meta"></head>
<body>

<!-- 插入公共模板 _header -->
<div th:replace="../templates/admin/common/_header :: common_header"></div>

<!-- 插入公共模板 _menu -->
<div th:replace="../templates/admin/common/_menu :: common_menu"></div>

<section class="Hui-article-box">
	<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 广告管理 <span class="c-gray en">&gt;</span> 广告列表<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
	<div class="Hui-article">
		<article class="cl pd-20">
			<div class="cl pd-5 bg-1 bk-gray mt-20">
				<span class="l">
					<a href="javascript:;" onclick="ad_stopBatch()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量关闭</a>
					<a href="javascript:;" onclick="ad_add('添加广告','goAdAdd','','650')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加广告</a>
				</span>
				<span class="r">共有数据：<strong th:text="${adVOList.size()}"></strong> 条</span>
			</div>
			<div class="mt-20">
				<table class="table table-border table-bordered table-hover table-bg table-sort">
					<thead>
						<tr class="text-c">
							<th width="25"><input type="checkbox" ></th>
							<th width="40">序号</th>
							<th width="300">广告图像</th>
							<th width="150">广告描述</th>
							<th width="160">广告链接</th>
							<th width="60">创建者</th>
							<th width="80">创建时间</th>
							<th width="80">更新时间</th>
							<th width="40">状态</th>
							<th width="50">操作</th>
						</tr>
					</thead>
					<tbody>
						<tr class="text-c" th:each="adVO,var : ${adVOList}">
							<td><input type="checkbox" th:value="${adVO.adId}" name="adId"></td>
							<td th:text="${var.count}"></td>
							<td><img style="width: 300px;height: 78px;" th:src="|@{'' + ${adVO.image} + ''}|"></td>
							<td th:text="${adVO.description}"></td>
							<td th:text="${adVO.url}"></td>
							<td th:text="${adVO.adminName}"></td>
							<td th:with="createTime=${adVO.createTime}" th:text="${#dates.format(createTime, 'yyyy-MM-dd HH:mm:ss')}"></td>
							<td th:with="updateTime=${adVO.updateTime}" th:text="${#dates.format(updateTime, 'yyyy-MM-dd HH:mm:ss')}"></td>
							<td class="td-status">
								<span class="label label-success radius" th:if="${adVO.state == 1}">开启</span>
								<span class="label label-defaunt radius" th:if="${adVO.state == 2}">关闭</span>
							</td>
							<td class="td-manage">
								<a th:if="${adVO.state == 1}" style="text-decoration:none" th:onClick="|ad_stop(this,${adVO.adId},'stop')|" href="javascript:;" title="关闭"><i class="Hui-iconfont">&#xe631;</i></a>
								<a th:if="${adVO.state == 2}" style="text-decoration:none" th:onClick="|ad_start(this,${adVO.adId},'start')|" href="javascript:;" title="开启"><i class="Hui-iconfont">&#xe6e1;</i></a>
								<a style="text-decoration:none" class="ml-5" th:onclick="|ad_edit('编辑','goAdEdit',${adVO.adId},'','650')|" title="编辑" href="javascript:;" ><i class="Hui-iconfont">&#xe6df;</i></a>
								<a title="删除" href="javascript:;" th:onclick="|ad_del(this,${adVO.adId})|" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>
							</td>
						</tr>
					</tbody>
				</table>
			</div>
		</article>
	</div>
</section>

<!-- 插入公共模版 _footer -->
<div th:replace="../templates/admin/common/_footer :: common_footer"></div>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="../../lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="../../lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../../lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" th:inline="none">

	/*广告-添加*/
	function ad_add(title,url,w,h){
		layer_show(title,url,w,h);
	}

	/*广告-编辑*/
	function ad_edit(title,url,adId,w,h){
		url = url + "?adId=" + adId;
		layer_show(title,url,w,h);
	}

	/*广告-删除*/
	function ad_del(obj,adId){
		layer.confirm('确认要删除吗？',function(index){
			$.ajax({
				type: "GET",
				dateType: "json",
				url: "doAdDelete",
				data: {adId:adId},
				success: function (result) {
					if(result.flag = "true") {
						$(obj).parents("tr").remove();
						layer.msg('已删除!',{icon:1,time:1000});
					} else {
						layer.msg('删除失败!',{icon: 2,time:1000});
					}
				},
				error: function (err) {
					layer.msg('请求异常!',{icon: 2,time:1000})
				}
			});

		});
	}

	/*广告-批量关闭*/
	function ad_stopBatch() {
		var obj = document.getElementsByName("adId");
		var adIds = [];
		for(i in obj) {
			if(obj[i].checked){
				adIds.push(obj[i].value);
			}
		}
		console.log(adIds);
		layer.confirm('确认要关闭吗？',function(index){
			$.ajax({
				type: "GET",
				dateType: "json",
				url: "doStopBatchAd",
				data: {adIds:adIds},
				success: function (result) {
					if(result.flag = "true") {
						layer.msg('关闭成功,请刷新!',{icon: 6,time:1000});
					} else {
						layer.msg('失败,含有'+result.number+'个关闭失败!',{icon: 2,time:1000});
					}
				},
				error: function (err) {
					layer.msg('请求异常!',{icon: 2,time:1000})
				}
			});
		});
	}

	/*广告-关闭*/
	function ad_stop(obj,adId,state){
		layer.confirm('确认要关闭吗？',function(index){
			$.ajax({
				type: "GET",
				dateType: "json",
				url: "doAdState",
				data: {adId:adId, state:state},
				success: function (result) {
					if(result.flag = "true") {
						$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="ad_start(this,'+adId+',\'start\')" href="javascript:;" title="开启"><i class="Hui-iconfont">&#xe6e1;</i></a>');
						$(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">关闭</span>');
						$(obj).remove();
						layer.msg('已关闭!',{icon: 5,time:1000});
					} else {
						layer.msg('关闭失败!',{icon: 2,time:1000});
					}
				},
				error: function (err) {
					layer.msg('请求异常!',{icon: 2,time:1000})
				}
			});
		});
	}

	/*广告-开启*/
	function ad_start(obj,adId,state){
		layer.confirm('确认要开启吗？',function(index){
			$.ajax({
				type: "GET",
				dateType: "json",
				url: "doAdState",
				data: {adId:adId, state:state},
				success: function (result) {
					if(result.flag = "true") {
						$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="ad_stop(this,'+adId+',\'stop\')" href="javascript:;" title="关闭"><i class="Hui-iconfont">&#xe631;</i></a>');
						$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">开启</span>');
						$(obj).remove();
						layer.msg('已开启!',{icon: 6,time:1000});
					} else {
						layer.msg('开启失败!',{icon: 2,time:1000});
					}
				},
				error: function (err) {
					layer.msg('请求异常!',{icon: 2,time:1000})
				}
			});
		});
	}


	/* 表格配置 */
	$(function(){
		$('.table-sort').dataTable({
			"aaSorting": [[ 1, "asc" ]],//默认第几个排序
			"bStateSave": true,//状态保存
			"aoColumnDefs": [
			  //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
			  {"orderable":false,"aTargets":[0,2,9]}// 制定列不参与排序
			]
		});


	});

</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>